package com.crm.system.controller.knowledgeitem;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.model.qo.knowledgeitem.KnowledgeItemQO;
import com.crm.system.service.knowledgeitem.KnowledgeItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 知识条目
 * @Author lixq-f
 * @Date 2021/5/7
 * @Version V1.0
 **/
@RequestMapping("/knowledgeItem")
@RestController
public class KnowledgeItemController {

    @Autowired
    private KnowledgeItemService itemService;


    @PostMapping("/addKnItem")
    public DataResponse addKnItem(@Validated @RequestBody KnowledgeItemQO itemQO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.insert(itemQO));
    }


    @GetMapping("/selectKnItemList")
    public DataResponse selectKnItemList() {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.selectList());
    }

    @PostMapping("/updateKnItem")
    public DataResponse updateKnItem(@Validated @RequestBody KnowledgeItemQO itemQO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.update(itemQO));
    }


    @GetMapping("/delKnItemById/{itemId}")
    public DataResponse deleteKnItemById(@PathVariable("itemId") String itemId) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.deleteById(itemId,
                (short) StatusCodeEnum.DELETE_CODE.getState()));
    }


    @GetMapping("/selectByKey/{itemId}")
    public DataResponse selectKnItemByKey(@PathVariable("itemId") String itemId) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), itemService.selectKnItemByKey(itemId));
    }


}
